package com.le.tester.onjava8.l_2_2_6;

/**
 * createTime：2023/1/7 15:58
 * description：克隆组合对象
 */
public class OceanReading implements Cloneable {

    private DepthReading depth;

    private TemperatureReading temperatureReading;

    public OceanReading(double tData, double dData) {
        temperatureReading = new TemperatureReading(tData);
        depth = new DepthReading(dData);
    }

    public OceanReading clone() {
        OceanReading or = null;
        try {
            or = (OceanReading) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        or.depth = or.depth.clone();
        or.temperatureReading = or.temperatureReading.clone();
        return or;
    }

    public DepthReading getDepth() {
        return depth;
    }

    public void setDepth(DepthReading depth) {
        this.depth = depth;
    }

    public TemperatureReading getTemperatureReading() {
        return temperatureReading;
    }

    public void setTemperatureReading(TemperatureReading temperatureReading) {
        this.temperatureReading = temperatureReading;
    }

    @Override
    public String toString() {
        return "temperature:" + temperatureReading + ",depth:" + depth;
    }
}
